package Demo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2022-12-04
 * Time: 8:19
 */
public class Thread_Demo7 {


    public static void main(String[] args) throws InterruptedException {
        // 创建锁
        Object lock1 = new Object(); // 加锁A
        Object lock2 = new Object(); // 加锁B
        Object lock3 = new Object(); // 加锁C

        // 创建线程
        Thread t1 = new Thread(() -> {
            System.out.println("A");
            synchronized (lock1) {
                lock1.notify();
            }
        });

        Thread t2 = new Thread(() -> {
            synchronized (lock1) {
                try {
                    lock1.wait();
                    System.out.println("B");

                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

            synchronized (lock2) {
                lock2.notify();
            }
        });

        Thread t3 = new Thread(() -> {
            synchronized (lock2) {
                try {
                    lock2.wait();
                    System.out.println("C");

                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });


        t3.start();
        t2.start();
        Thread.sleep(1000); // 确保t2 t3 先执行
        t1.start();

    }


}
